import hashlib
import random
import string

from setting.member_path import *


def md5_pwd(pwd):
    md5 = hashlib.md5()
    md5.update(pwd.encode('utf-8'))
    pwd = md5.hexdigest()
    return pwd

def creat_case():
    dir = os.listdir(MEMBER_PATH)
    for file in dir:
        if file.endswith('.yaml') or file.endswith('.yml'):
            file = file.replace('.yaml','').replace('.yml','')
            class_name = file.capitalize()
            file_name = file
            case_name = file.lower()
            template_name = os.path.join(TEMPLATE_PATH,'member_template.txt')
            with open(template_name,'r',encoding='utf-8') as rf:
                content = rf.read()%{
                    'class_name':class_name,
                    'case_name':case_name,
                    'file_name':file_name
            }
            case_file = os.path.join(CASE_PATH, 'test_%s.py' % file_name)
            with open(case_file,'w',encoding='utf-8') as wf:
                wf.write(content)
def name_generator(size=6,chars=string.ascii_lowercase+string.digits):
    """生成随机用户名"""
    username = ''.join(random.choice(chars) for _ in range(size))
    return username